package ar.edu.itba.pod.printer.impl;

import ar.edu.itba.pod.printer.Document;
import ar.edu.itba.pod.printer.Printer;

public class ThreadPrinter extends Thread{
	
	private Printer printer= new Printer();
	private volatile Document document;
	private boolean finish;
	private volatile boolean busy;
	
	
	public ThreadPrinter(String name) {
		super(name);
		System.out.println(name);
	}
	
	@Override
	public void run() {
		while(!finish){
			if(document!=null){
				System.out.print("S:" + getName() + "(" + 
						document.getNumberOfPages() + ")");
				busy=true;
				printer.print(document);
				System.out.println("F:" + getName());
				busy=false;
				document=null;
			}
		}
	}
	
	public void addJob(Document document){
		this.document=document;
	}
	
	public boolean isBusy() {
		return busy;
	}
	
	void finish() {
		interrupt();
		System.out.println( getName() + " Terminando");
		finish=true;
	}

}
